home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / DB_CLIPP / 2510.ZIP / TRSOURCE.EXE / LOGNBASX.C < prev    next >
C/C++ Source or Header  |  1990-10-22  |  885b  |  40 lines

  1. /*********
  2. *
  3. * LOGNBASX.C
  4. *
  5. * by Ralph Davis
  6. *
  7. * Placed in the public domain by Tom Rettig Associates, 10/22/1990.
  8. *
  9. *  Syntax:  LOGNBASX( <expN1>, <expN2> )
  10. *  Return:  The log of <expN1> to the base <expN2> 
  11. *               if both <expN1> and <expN2> >= 0
  12. *           INFINITY() if either is negative
  13. *********/
  14.  
  15. #include "trlib.h"
  16.  
  17. TRTYPE lognbasx()
  18. {
  19.    double n1, n2, ret;
  20.  
  21.    if ( PCOUNT == 2 && ISNUM(1) && ISNUM(2) )
  22.    {
  23.       n1 = _parnd(1);
  24.       n2 = _parnd(2);
  25.      
  26.       if ( n1 < 0 || n2 <= 0 )   /* No negatives, and n2 cannot
  27.                                     be 0 */
  28.          _retnd(_tr_infinity());
  29.       else
  30.       {
  31.          /* Log of n1 to the base n2 = Log(n1) divided by Log(n2) */
  32.  
  33.          ret = _tr_log(n1) / _tr_log(n2);  
  34.          _retnd( ret );
  35.       }
  36.    }
  37.    else
  38.       _retnd(ERRORNEG);   /* -1 if error */
  39. }
  40.